"""
example05 - 字符串的操作

Author: Administrator
Date: 2024/1/11
"""

a = 'hello,world'
# 居中
print(a.center(80, '~'))
# 右对齐
print(a.rjust(80, '~'))
# 左对齐
print(a.ljust(80, '~'))

b = '123'
# 零填充（在左边补0）
print(b.zfill(6))

c = 1234
d = 345
print('%d + %d = %d' % (c, d, c + d))
# Python 3.6引入的格式化字符串的便捷语法
print(f'{c} + {d} = {c + d:,}')
print(f'{c} + {d} = {c + d:.4e}')
print(f'{c} + {d} = {c + d:.4%}')
# 和上面的语法等价
print('{} + {} = {}'.format(c, d, c + d))
print('{0} + {1} = {2}'.format(c, d, c + d))
